import configparser
import json
import os
import re

class ConfigLoader:

    def __init__(self, env='a'):
        self.env = f"ssts-{env}"
        self.config = configparser.ConfigParser()
        self.config.read('config/env_config.ini', encoding='utf-8')

        if not self.config.has_section(self.env):
            raise ValueError(f"环境配置不存在: {self.env}")

    @property
    def base_url(self):
        return self.config.get(self.env, 'base_url')

    @property
    def test_data(self):
        data_file = self.config.get(self.env, 'data_file')
        if not os.path.exists(data_file):
            raise FileNotFoundError(f"测试数据文件不存在: {data_file}")

        with open(data_file, 'r', encoding='utf-8') as f:
            return json.load(f)